package MaintMenu.VenPricingUpdTBLN;

import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

//import java.sql.SQLException;

public class testTBL {
    public testTBL()
    {
        int x=0;
        int y=0;
//        try {
//            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//            String dataSourceName = "dbLI";
//            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
//            Connection conli = DriverManager.getConnection(dbURL, "", "");
////            String st[] = new String[1];
////            st[0] = ("UPDATE  tblinventory SET prpkey=555 WHERE partslink=NI1248103");
////            st[1] = ("UPDATE tblinventory AS a INNER JOIN tblmrn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");
////
////            st[2] = ("UPDATE tblinventory AS a INNER JOIN tblotn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");
////
////            st[3] = ("UPDATE tblinventory AS a INNER JOIN tblltn AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");
////
////            st[4] = ("UPDATE tblinventory AS a INNER JOIN tblcln AS b ON a.[Part#] = b.[Part#] SET a.partslink = b.partlink;");
//            Statement stli = conli.createStatement();
//            stli.execute("update tblinventory set Make='a', Mdl='b', ModelType='C' where [part#]='ad101';");
////            for (x=1; x<st.length;x++){
////                Statement stli = conli.createStatement();
////                try {
////                    stli.execute(st[x]);
////                }catch(SQLException er) {
////                    er.printStackTrace();
////                }stli.close();
////            }
//        }
//        catch(Exception e)
//        {
//
//            e.printStackTrace();
//            JOptionPane.showMessageDialog(null, e);
//        }

        int filesToUpdate=1;
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String dataSourceName = "dbLI";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection conli = DriverManager.getConnection(dbURL, "", "");
            Statement stli = conli.createStatement();
            Statement stli1 = conli.createStatement();


//            System.out.println(" Step 1");
            stli.execute("SELECT * FROM _COSTTYGTX3");
//            System.out.println("Total record Updated : "+rowsupdated1);

            ResultSet rs = stli.getResultSet();
            if (rs != null)
                while (rs.next()) {
//                    System.out.println(" Step 2");

//                    System.out.println("Script :"+x);
//                    System.out.println(st[x]);
//                    int rowsupdated = stli.executeUpdate(st[x]);
//                    System.out.println("Total record Updated : "+rowsupdated);
                    int rowupdated=0;
                    String tygp = rs.getString("TYGP #");
                    String tygp1 = tygp.substring(tygp.length() - 1);
                    char tygpchar =   tygp1.charAt(0);

                    String capa = rs.getString("CAPA");
//                    System.out.println(tygp1);
//                    System.out.println(tygp+" "+capa);
                    if (tygpchar=='Q'){
                        System.out.println(tygp1+" its capa "+ tygp +" "+capa);
                        String st="UPDATE _cOSTTYGTX3 SET CAPA=  WHERE [TYGP #]=\""+tygp+"\"";
                        System.out.println(st);
                        stli1.executeUpdate(st);
//                        System.out.println("Total record Updated : "+rowupdated);
                        System.out.println("Updated " + tygp + " capa to  " + capa);

                    }

//                try {
//                    stli.execute("update TBLBCN set REMARK = REMARK & ' ' & '" + a + "' WHERE [PART#] = '" + b + "';");
//                } catch (SQLException er) {
//                }
                }

        }catch(Exception e){
            e.printStackTrace();
        }

    }
}
